package com.upb.webserver.dao.mapper;

import com.upb.webserver.common.pojo.order.ApplicationUnionOrder;
import com.upb.webserver.common.pojo.order.ApplicationUnionOrderParam;
import com.upb.webserver.common.pojo.order.ChainUnionOrder;
import com.upb.webserver.common.pojo.order.ChainUnionOrderParam;
import com.upb.webserver.dao.entity.TbWorkOrder;
import com.upb.webserver.dao.entity.TbWorkOrderExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Optional;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

public interface TbWorkOrderMapper {

    @Select({"select", TbWorkOrderSqlProvider.ALL_COLUMN_FIELDS, "from tb_work_order", "where detail like concat('%\"crossChainName\":\"',", "#{crossName,jdbcType=VARCHAR}", ",'\"%')"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    List<TbWorkOrder> listByNameOfCrossChain(@Param("crossName") String crossName);


    @Delete({"<script>", "delete from tb_work_order", "where target_table = #{targetTable,jdbcType=VARCHAR} and target_id in", "<foreach collection='targetIdList' item='targetId' open='(' separator=',' close=')'>", "#{targetId}", "</foreach>", "</script>"})
    int deleteByTargetTableAndTargetIdList(@Param("targetTable") String tableName, @Param("targetIdList") List<Integer> targetIdList);

    @Select({"select", TbWorkOrderSqlProvider.ALL_COLUMN_FIELDS, "from tb_work_order", "where type = #{type,jdbcType=TINYINT} and  status = #{status,jdbcType=TINYINT}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    List<TbWorkOrder> listByTypeAndStatus(@Param("type") Byte type, @Param("status") Byte status);

    @Select({"select", TbWorkOrderSqlProvider.ALL_COLUMN_FIELDS, "from tb_work_order", "where target_table = #{targetTable,jdbcType=VARCHAR} and  target_id = #{targetId,jdbcType=INTEGER}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    TbWorkOrder selectByTargetTableAndTargetId(@Param("targetTable") String tableName, @Param("targetId") Integer targetId);

    @Delete({"delete from tb_work_order", "where detail like concat('%\"chainId\":',", "#{chainId,jdbcType=INTEGER}", ",'%')"})
    int deleteAllApplicationByChainId(@Param("chainId") Integer chainId);

    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "unionQueryFromChainAndWorkOrder")
    @Results({@Result(column = "chainId", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "workOrderId", property = "workOrderId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP)})
    List<ChainUnionOrder> unionQueryFromChainAndWorkOrder(ChainUnionOrderParam param);

    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "unionQueryCountFromChainAndWorkOrder")
    long unionQueryCountFromChainAndWorkOrder(ChainUnionOrderParam param);

    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "unionQueryFromApplicationAndWorkOrder")
    @Results({@Result(column = "applicationId", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "workOrderId", property = "workOrderId", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP)})
    List<ApplicationUnionOrder> unionQueryFromApplicationAndWorkOrder(ApplicationUnionOrderParam param);

    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "unionQueryCountFromApplicationAndWorkOrder")
    long unionQueryCountFromApplicationAndWorkOrder(ApplicationUnionOrderParam param);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "countByExample")
    long countByExample(TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbWorkOrderSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Delete({"delete from tb_work_order", "where id = #{id,jdbcType=INTEGER}"})
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Insert({"insert into tb_work_order (type, status, ", "target_table, target_id, ", "create_from_platform, create_by, ", "modify_by, close_by_manager, ", "gmt_create, gmt_modified, ", "detail, description)", "values (#{type,jdbcType=TINYINT}, #{status,jdbcType=TINYINT}, ", "#{targetTable,jdbcType=VARCHAR}, #{targetId,jdbcType=INTEGER}, ", "#{createFromPlatform,jdbcType=TINYINT}, #{createBy,jdbcType=INTEGER}, ", "#{modifyBy,jdbcType=INTEGER}, #{closeByManager,jdbcType=INTEGER}, ", "#{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, ", "#{detail,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR})"})
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbWorkOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbWorkOrderSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbWorkOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    List<TbWorkOrder> selectByExampleWithBLOBs(TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "selectByExample")
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP)})
    List<TbWorkOrder> selectByExample(TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Select({"select", "id, type, status, target_table, target_id, create_from_platform, create_by, ", "modify_by, close_by_manager, gmt_create, gmt_modified, detail, description", "from tb_work_order", "where id = #{id,jdbcType=INTEGER}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    TbWorkOrder selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbWorkOrderSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbWorkOrder record, @Param("example") TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbWorkOrderSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") TbWorkOrder record, @Param("example") TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbWorkOrderSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbWorkOrder record, @Param("example") TbWorkOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbWorkOrderSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbWorkOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Update({"update tb_work_order", "set type = #{type,jdbcType=TINYINT},", "status = #{status,jdbcType=TINYINT},", "target_table = #{targetTable,jdbcType=VARCHAR},", "target_id = #{targetId,jdbcType=INTEGER},", "create_from_platform = #{createFromPlatform,jdbcType=TINYINT},", "create_by = #{createBy,jdbcType=INTEGER},", "modify_by = #{modifyBy,jdbcType=INTEGER},", "close_by_manager = #{closeByManager,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},", "detail = #{detail,jdbcType=LONGVARCHAR},", "description = #{description,jdbcType=LONGVARCHAR}", "where id = #{id,jdbcType=INTEGER}"})
    int updateByPrimaryKeyWithBLOBs(TbWorkOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Update({"update tb_work_order", "set type = #{type,jdbcType=TINYINT},", "status = #{status,jdbcType=TINYINT},", "target_table = #{targetTable,jdbcType=VARCHAR},", "target_id = #{targetId,jdbcType=INTEGER},", "create_from_platform = #{createFromPlatform,jdbcType=TINYINT},", "create_by = #{createBy,jdbcType=INTEGER},", "modify_by = #{modifyBy,jdbcType=INTEGER},", "close_by_manager = #{closeByManager,jdbcType=INTEGER},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=INTEGER}"})
    int updateByPrimaryKey(TbWorkOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({"<script>", "insert into tb_work_order (type, ", "status, target_table, ", "target_id, create_from_platform, ", "create_by, modify_by, ", "close_by_manager, gmt_create, ", "gmt_modified, detail, ", "description)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.type,jdbcType=TINYINT}, ", "#{detail.status,jdbcType=TINYINT}, #{detail.targetTable,jdbcType=VARCHAR}, ", "#{detail.targetId,jdbcType=INTEGER}, #{detail.createFromPlatform,jdbcType=TINYINT}, ", "#{detail.createBy,jdbcType=INTEGER}, #{detail.modifyBy,jdbcType=INTEGER}, ", "#{detail.closeByManager,jdbcType=INTEGER}, #{detail.gmtCreate,jdbcType=TIMESTAMP}, ", "#{detail.gmtModified,jdbcType=TIMESTAMP}, #{detail.detail,jdbcType=LONGVARCHAR}, ", "#{detail.description,jdbcType=LONGVARCHAR})</foreach></script>"})
    int batchInsert(List<TbWorkOrder> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_work_order
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbWorkOrderSqlProvider.class, method = "getOneByExample")
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "type", property = "type", jdbcType = JdbcType.TINYINT), @Result(column = "status", property = "status", jdbcType = JdbcType.TINYINT), @Result(column = "target_table", property = "targetTable", jdbcType = JdbcType.VARCHAR), @Result(column = "target_id", property = "targetId", jdbcType = JdbcType.INTEGER), @Result(column = "create_from_platform", property = "createFromPlatform", jdbcType = JdbcType.TINYINT), @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.INTEGER), @Result(column = "modify_by", property = "modifyBy", jdbcType = JdbcType.INTEGER), @Result(column = "close_by_manager", property = "closeByManager", jdbcType = JdbcType.INTEGER), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP), @Result(column = "detail", property = "detail", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "description", property = "description", jdbcType = JdbcType.LONGVARCHAR)})
    Optional<TbWorkOrder> getOneByExample(TbWorkOrderExample example);
}
